<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p><input type="checkbox" name="" id="checkAll"></p>
    <p>
        <input type="checkbox" name="" class="checkOne">
        <input type="checkbox" name="" class="checkOne">
        <input type="checkbox" name="" class="checkOne">
        <input type="checkbox" name="" class="checkOne">
    </p>
    <script>
    var checkall=document.getElementById("checkAll");
    var cheklist=document.getElementsByTagName("p")[1].children;
    // var checkone=document.getElementById("checkOne");   
    checkall.onclick=function(){
        var flag=checkall.checked
        for (var i=0;i<cheklist.length;i++) {
            cheklist[i].checked=flag
        }
    }
    for(var i=0;i<cheklist.length;i++){
        cheklist[i].onclick=function(){
            checkall.checked=false
            var count=0;
            for(var j=0;j<cheklist.length;j++){
                console.log(cheklist[j].checked)
                if(cheklist[j].checked){
                    count++
                }
            }
            if(count==cheklist.length){
                checkall.checked=true
            }
        }
    }
    </script>
</body>
</html>